package Controller;

import org.zkoss.bind.ValidationContext;
import org.zkoss.bind.validator.AbstractValidator;
/**
 * Validator class accesses the properties of the grading key and checks whether the grading key is ordered linear
 * @author Rupert
 *
 */
public class ExamEditorGradingValidator extends AbstractValidator {

	@Override
	public void validate(ValidationContext ctx) {
		double grade10 = new Double(ctx.getProperties("grade10")[0].getValue().toString());
		double grade13 = new Double(ctx.getProperties("grade13")[0].getValue().toString());
		double grade17 = new Double(ctx.getProperties("grade17")[0].getValue().toString());
		double grade20 = new Double(ctx.getProperties("grade20")[0].getValue().toString());
		double grade23 = new Double(ctx.getProperties("grade23")[0].getValue().toString());
		double grade27 = new Double(ctx.getProperties("grade27")[0].getValue().toString());
		double grade30 = new Double(ctx.getProperties("grade30")[0].getValue().toString());
		double grade33 = new Double(ctx.getProperties("grade33")[0].getValue().toString());
		double grade37 = new Double(ctx.getProperties("grade37")[0].getValue().toString());
		double grade40 = new Double(ctx.getProperties("grade40")[0].getValue().toString());
		double grade43 = new Double(ctx.getProperties("grade43")[0].getValue().toString());
		double grade47 = new Double(ctx.getProperties("grade47")[0].getValue().toString());
		
		String errorMessage = "Error with the grading key! Must be ordered linear!";
		
		if(grade10<grade13)
			this.addInvalidMessage(ctx, "gradeMistake" , errorMessage);
		
		if(grade13<grade17)
			this.addInvalidMessage(ctx, "gradeMistake", errorMessage);	
		
		if(grade17<grade20)
			this.addInvalidMessage(ctx, "gradeMistake", errorMessage);	
		
		if(grade20<grade23)
			this.addInvalidMessage(ctx, "gradeMistake", errorMessage);	
		
		if(grade23<grade27)
			this.addInvalidMessage(ctx, "gradeMistake", errorMessage);	
		
		if(grade27<grade30)
			this.addInvalidMessage(ctx, "gradeMistake", errorMessage);
		
		if(grade30<grade33)
			this.addInvalidMessage(ctx, "gradeMistake", errorMessage);
		
		if(grade33<grade37)
			this.addInvalidMessage(ctx, "gradeMistake", errorMessage);
		
		if(grade37<grade40)
			this.addInvalidMessage(ctx, "gradeMistake", errorMessage);
		
		if(grade40<grade43)
			this.addInvalidMessage(ctx, "gradeMistake", errorMessage);	
		
		if(grade43<grade47)
			this.addInvalidMessage(ctx, "gradeMistake", errorMessage);
		
		
	}

}
